package com.hhkj.api.invoice.controller;

import com.hhkj.api.invoice.model.req.ApiInvoicePagingReq;
import com.hhkj.api.invoice.model.req.ApiInvoiceReq;
import com.hhkj.api.invoice.service.biz.ApiSaleInvoiceBizService;
import com.hhkj.api.sale.common.session.model.LoginSale;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.login.api.ApiLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * ApiSaleInvoiceController
 *
 * @author HHKJ-SERVER-ZJ
 * @since 2023/11/6 16:26
 */
@RequestMapping("/api/sale/invoice")
@RestController
public class ApiSaleInvoiceController extends BaseController {

    @Autowired
    private ApiSaleInvoiceBizService invoiceBizService;

    /** 获取详情 */
    @ApiLogin(LoginSale.class)
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable("id") Long id) {
        return AjaxResult.success(invoiceBizService.getById(id));
    }

    /** 分页 */
    @ApiLogin(LoginSale.class)
    @PostMapping("/paging")
    public TableDataInfo paging(@RequestBody ApiInvoicePagingReq req) {
        startPageBody(req);
        return getDataTable(invoiceBizService.paging(req));
    }

    /** 申请开票 */
    @ApiLogin(LoginSale.class)
    @PostMapping("")
    public AjaxResult save(@Validated @RequestBody ApiInvoiceReq req) {
        return invoiceBizService.save(req) ? AjaxResult.success() : AjaxResult.error();
    }
}
